<template>
  <div class="person-container">
    <!-- 个人信息卡片 -->
    <div class="profile-card">
      <div class="profile-header">
        <!-- 头像区域 -->
        <div class="avatar-section">
          <div class="avatar-wrapper">
            <img 
              :src="require(`@/assets/avatar/${userInfo.upic || '1'}.png`)" 
              alt="用户头像"
              class="avatar-image"
            />
            <div class="avatar-overlay">
              <i class="el-icon-camera"></i>
            </div>
          </div>
        </div>
        
        <!-- 基本信息区域 -->
        <div class="basic-info">
          <h2 class="username">{{ userInfo.uname }}</h2>
          <p class="user-id">账号：{{ userInfo.uid  }}</p>
        </div>
      </div>

      <!-- 统计数据卡片组 -->
      <div class="stats-cards">
        <div class="stat-card" @click="goToCertificates">
          <i class="el-icon-medal"></i>
          <div class="stat-content">
            <span class="stat-number">{{ certificates }}</span>
            <span class="stat-label">证书数量</span>
          </div>
        </div>
        <div class="stat-card" @click="goToApplications">
          <i class="el-icon-document"></i>
          <div class="stat-content">
            <span class="stat-number">{{ applications }}</span>
            <span class="stat-label">申请数量</span>
          </div>
        </div>
        <div class="stat-card" @click="goToList">
          <i class="el-icon-collection"></i>
          <div class="stat-content">
            <span class="stat-number">{{ listCount }}</span>
            <span class="stat-label">清单数量</span>
          </div>
        </div>
      </div>
    </div>

    <!-- 详细信息卡片 -->
    <div class="detail-card">
      <h3 class="section-title">
        <i class="el-icon-user"></i>
        详细信息
      </h3>
      <div class="info-grid">
        <div class="info-item">
          <span class="info-label">真实姓名</span>
          <span class="info-value">{{ userInfo.urealName }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">联系方式</span>
          <span class="info-value">{{ userInfo.unum }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">邮箱地址</span>
          <span class="info-value">{{ userInfo.uemail }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">所属公司</span>
          <span class="info-value">{{ userInfo.ucompany }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Person',
  data() {
    return {
      userInfo: {},
      certificates: 0,
      applications: 0,
      listCount: 0,
    }
  },
  created:function(){

      this.fetchUserInfo();
      this.fetchCertificates();
      this.fetchApplications();
      this.fetchList();
      this.fetchLists();

},
mounted:function() {

},

  methods: {
    // 保持原有的方法不变...
    fetchUserInfo() {
      this.$http.get("/findUserById").then((response) => {
        this.userInfo = response.data;
      }).catch((error) => {
        console.error("获取用户信息失败:", error);
      });
    },
    fetchCertificates() {
      this.$http.get("/findPmcNumByUID").then((response) => {
        this.certificates = response.data;
      }).catch((error) => {
        console.error("获取证书数量失败:", error);
      });
    },
    fetchApplications() {
      this.$http.get("/findComparisonNumByUID").then((response) => {
        this.applications = response.data;
      }).catch((error) => {
        console.error("获取申请数量失败:", error);
      });
    },
    fetchList() {
      this.$http.get("/findSpoNumByUID").then((response) => {
        this.listCount = response.data;
      }).catch((error) => {
        console.error("获取清单数量失败:", error);
      });
    },
    fetchLists() {
      this.$http.get("/findOrdersNumByUID").then((response) => {
        this.listCount += response.data;
      }).catch((error) => {
        console.error("获取订单数量失败:", error);
      });
    },
    goToCertificates() {
      this.$router.push('/certificate/certificate')
    },
    goToApplications() {
      this.$router.push('/application/application-records')
    },
    goToList() {
      this.$router.push('/sample')
    }
  }
}
</script>

<style scoped>
.person-container {
  padding: 24px;
  background-color: #f0f2f5;
  min-height: 100vh;
}

.profile-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 24px;
  margin-bottom: 24px;
}

.profile-header {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
}

.avatar-section {
  margin-right: 24px;
}

.avatar-wrapper {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
}

/* .avatar-wrapper:hover .avatar-overlay {
  opacity: 1;
} */

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.avatar-overlay i {
  color: white;
  font-size: 24px;
}

.basic-info {
  flex-grow: 1;
}

.username {
  font-size: 24px;
  color: #303133;
  margin: 0 0 8px 0;
}

.user-id {
  color: #909399;
  margin: 0;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-top: 24px;
}

.stat-card {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  align-items: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat-card i {
  font-size: 24px;
  color: #409EFF;
  margin-right: 16px;
}

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-number {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
}

.stat-label {
  font-size: 14px;
  color: #909399;
  margin-top: 4px;
}

.detail-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 24px;
}

.section-title {
  display: flex;
  align-items: center;
  color: #303133;
  margin: 0 0 24px 0;
}

.section-title i {
  margin-right: 8px;
  color: #409EFF;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.info-item {
  padding: 16px;
  background: #f8f9fa;
  border-radius: 6px;
  transition: background-color 0.3s ease;
}

.info-item:hover {
  background: #f0f7ff;
}

.info-label {
  display: block;
  color: #909399;
  font-size: 14px;
  margin-bottom: 8px;
}

.info-value {
  color: #303133;
  font-size: 16px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .stats-cards {
    grid-template-columns: 1fr;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .profile-header {
    flex-direction: column;
    text-align: center;
  }

  .avatar-section {
    margin-right: 0;
    margin-bottom: 16px;
  }
}
</style>
